<template>
	<view>
		<cu-custom>
			<block slot="content">邀请函</block>
		</cu-custom>
		<view class="p-t-10 p-b-20" :style="{height:(windowHeight - CustomBar - 66)+'px'}">
			<carousel :img-list="imgList" url-key="img" @selected="selectedBanner" @changes="changes" />
		</view>
		<view style="height: 66px;"></view>
		<view class="bottom-wrap flex justify-space-around">
			<view class="bottom-btn bottom-btn2" @click="sub()">
				邀请好友
			</view>
		</view>
		<view class="masks" @click="hidMask" :style="{height:(windowHeight)+'px'}" v-show="maskShow">
			<view class="masks-tip">
				请点击右上角分享
			</view>
		</view>
	</view>
</template>

<script>
	import wx from 'weixin-js-sdk';
	import carousel from '@/components/vear-carousel/vear-carousel';
	export default {
		components: {
			carousel
		},
		data() {
			return {
				CustomBar: this.CustomBar,
				windowHeight: 675,
				imgList: [],
				id: 0,
				current: 0,
				maskShow: false
			}
		},
		onLoad(option) {
			if (option.id) {
				this.id = option.id;
			}
			this.windowHeight = uni.getSystemInfoSync().windowHeight;
			this.getInfo();
			this.getMine();
		},
		methods: {
			selectedBanner(item, index) {
				console.log('🥒', item, index)
			},
			changes(index) {
				console.log('🥒', index)
				this.current = index;
			},
			getMine() {
				let data = {

				}
				this.$http('/apicloud/User/userInfo', data).then(res => {
					if (res.code == 200) {
						let datas = res.data;
						this.names = datas.name;
					}
				})
			},
			getInfo() {
				let data = {

				}
				this.$http('/apicloud/User/invitation', data).then(res => {
					if (res.code == 200) {
						this.imgList = res.data;
						this.getToken();
					}
				})
			},
			sub() {
				this.maskShow = true;
			},
			hidMask() {
				this.maskShow = false;
			},
			isIOSWechat() {
			  const ua = navigator.userAgent.toLowerCase();
			  return /iphone|ipad|ipod/.test(ua) && /micromessenger/.test(ua);
			},
			getToken() {
				console.log(location.href, 'config1')
				let url = '';
				url = location.href.split('#')[0];
				let data = {
					// url: 'http://xmtzx.cqyouths.com/index/index/noPublic.html'
					url
				}
				this.$http('/apicloud/User/getPositioningTicket', data).then(res => {
					console.log(res, 'config1');
					wx.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: res.data.appId, // 必填，公众号的唯一标识
						timestamp: res.data.jsTimesTamp, // 必填，生成签名的时间戳
						nonceStr: res.data.jsNonceStr, // 必填，生成签名的随机串
						signature: res.data.jsSignature, // 必填，签名
						jsApiList: ['updateAppMessageShareData',
						'updateTimelineShareData'], // 必填，需要使用的JS接口列表
					});
					let info = this.imgList[this.current];
					wx.ready(() => {
						setTimeout(()=>{
							wx.updateAppMessageShareData({
								title: info.name, // 分享标题
								desc: '诚挚邀请', // 分享描述
								link: `${this.$url}/userh5/pages/operate/inviteShow?id=${info.id}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
								imgUrl: info.img, // 分享图标
								success: function(ress) {
									// 设置成功
									console.log('成功了=',ress)
								},
								fail:(rej)=>{
									console.log('失败了=',rej)
								}
							})
							wx.updateTimelineShareData({
								title: info.name, // 分享标题
								link: `${this.$url}/userh5/pages/operate/inviteShow?id=${info.id}`, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
								imgUrl: info.img, // 分享图标
								success: function() {
									// 设置成功
								}
							})
						},300)
					})
					wx.error((rej)=> {
						if(this.isIOSWechat()){
							window.location.reload();
						}
					})
				})
			},
		}
	}
</script>

<style lang="less">
	.imgs {
		width: 160rpx;
		height: 160rpx;
		border-radius: 16rpx;
	}

	.bottom-wrap {
		box-shadow: 0px -3px 6px rgba(0, 0, 0, 0.07);
		border-radius: 20px 20px 0 0;
		height: 66px;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 100;
		background: #ffffff;
		width: 100%;
		padding: 15rpx 30rpx 0 30rpx;

		.bottom-btn {
			width: 100%;
			height: 76rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ffffff;
			font-weight: bold;
			border-radius: 60rpx;
		}


		.bottom-btn2 {
			background: #FF5200;
		}
	}

	.masks {
		background: rgba(0, 0, 0, 0.4);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 500;
		width: 100%;
	}

	.masks-tip {
		background: #FF5200;
		color: #fff;
		position: absolute;
		right: 30rpx;
		top: 40rpx;
		padding: 20rpx 40rpx;
		border-radius: 10rpx;
	}

	.masks-tip::after {
		content: '';
		width: 0;
		height: 0;
		position: absolute;
		top: -44rpx;
		right: 10%;
		border-top: 20rpx solid transparent;
		border-bottom: 20rpx solid #FF5200;
		border-left: 20rpx solid transparent;
		border-right: 20rpx solid transparent;
	}
</style>